import { create } from 'dva-core';
import createLoading from 'dva-loading';
// import { createLogger } from 'redux-logger';

let app
let store
let dispatch
let registered
const createApp=(opt) => {
  // opt.onAction = [createLogger()]
  const {models}=opt
  app = create(opt)
  app.use(createLoading({}))

  if (!registered) {
    models.forEach(model => app.model(model))
  }
  registered = true
  app.start()
  store = app._store
  app.getStore = () => store
  dispatch = store.dispatch
  app.dispatch = dispatch
  return app
}

export default {
  createApp,
  getDispatch: () =>  app.dispatch
}
